<?php
session_start();
require_once("include/auth.php");


$currentUser = current_user();
//todo: add the gets
//$facultyName = $_POST['facultyName'];
//$gender = $_POST['gender'];
//$address = $_POST['address'];
//$permAddress = $_POST['permAddress'];
//$dept = $_POST['dept'];
//$email = $_POST['email'];
//$position = $_POST['position'];


//if no current user then redirect to login screen
if (!$currentUser){
    redirect("signin.php",null);



}
else{
    $facName = $currentUser['Name'];
    $departments = getDepartments();


}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Personal Information</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="calendar.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("select#course_drop_down").attr("disabled","disabled");
            $("select#dept_drop_down").change(function(){
                var id = $("select#dept_drop_down option:selected").attr('value');
                dynamicDropDown("select#course_drop_down","get_courses_for_dept.php",{dept_id:id}, "Course_Title", "Course_Title");
            });

            $("select#section_drop_down").attr("disabled","disabled");
            $("select#term_drop_down").change(function(){
                var id = $("select#course_drop_down option:selected").attr('value');
                var id2 = $("select#term_drop_down option:selected").attr('value');
                dynamicDropDown("select#section_drop_down","get_sections_for_course.php",{course_title:id,course_term:id2}, "Letter", "Letter");
            });

            $("select#term_drop_down").attr("disabled","disabled");
            $("select#course_drop_down").change(function(){
                var id = $("select#course_drop_down option:selected").attr('value');

                dynamicDropDown("select#term_drop_down","get_terms_for_course.php",{course_title:id}, "Term", "Term");
            });

        });

        function dynamicDropDown(drop_down_id, url, params, value_name, display_name  ){

            $(drop_down_id).attr("disabled","disabled");
            $(drop_down_id).html("<option>wait...</option>");

            $.get(url, params, function(data){
                $(drop_down_id).removeAttr("disabled");
                $(drop_down_id).html("<option>Select an option...</option>");
                for (var i=0;i<data.length;i++)
                {
                    var item = data[i];
                    var optionNode = $('<option></option>').attr('value', item[value_name]).text(item[display_name]);
                    $(drop_down_id).append(optionNode);
                }

            });

        }
    </script>
</head>
<body id="main_body" >
	
	<img id="top" src="top.png" alt="">
	<div id="form_container">
	
		<h1><a>Faculty Personal Information</a></h1>
		<form id="form_528101" class="appnitro"  method="post" action="faculty_personal_info_action.php">
					<div class="form_description">
			<h2>Faculty Personal Information</h2>
			<p></p>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="fac_name">Name </label>
		<div>
			<input id="fac_name" name="fac_name" class="element text large" type="text" maxlength="255" value="<?=$facName?>"/>
		</div> 
		</li>		<li id="li_5" >
		<label class="description" for="dob">Date of Birth </label>
		<div>
			<input id="dob" name="dob" class="element text" size="10" maxlength="12" value="<?=$currentUser['Date_Of_Birth']?>" type="text">
			<label for="element_5_1">YYYY-MM-DD</label>
		</div>

	

		 
		</li>		<li id="li_4" >
		<label class="description" for="gender">Gender </label>
		<div>
		<select class="element select small" id="gender" name="gender">
			<option value="" selected="selected"></option>
<option value="M" >Male</option>
<option value="F" >Female</option>

		</select>
		</div> 
		</li>		<li id="li_6" >
		<label class="description" for="address">Address </label>
		
		<div>
			<input id="address" name="address" class="element text large" value="<?=$currentUser['Address']?>" type="text">
			<label for="address">Street Address</label>
		</div>
	


		</li>		<li id="li_7" >
		<label class="description" for="perm_address">Permanent Address </label>
		
		<div>
			<input id="perm_address" name="perm_address" class="element text large" value="<?=$currentUser['Permanent_Address']?>" type="text">
			<label for="perm_address">Street Address</label>
		</div>
	

		</li>		<li id="li_8" >
		<label class="description" for="contact_no">Contact Number </label>
            <div>
			<input id="contact_no" name="contact_no" class="element text small" size="10" maxlength="10" value="<?=$currentUser['Contact_No']?>" type="text">
			<label for="contact_no">e.g. 55555555555</label>
            </div>

		 
		</li>		<li id="li_9" >
		<label class="description" for="email">Email Address </label>
		<div>
			<input id="email" name="email" class="element text medium" type="text" maxlength="255" value="<?=$currentUser['Email_ID']?>"/>
		</div> 
		</li>		<li id="li_16" >
		<label class="description" for="dept_drop_down">Department </label>
		<div>
		<select class="element select medium" id="dept_drop_down" name="dept_drop_down">
			<option value="" selected="selected"></option>
            <?php foreach($departments as $dept){ ?>
                <option value="<?= $dept->Dept_ID ?>"><?= $dept->Dept_Name ?></option>
            <?php } ?>

		</select>
		</div> 
		</li>		<li id="li_17" >
		<label class="description" for="position">Position</label>
		<div>
		<select class="element select medium" id="position" name="position">
			<option value="" selected="selected"></option>
            <option value="1" >Professor</option>
            <option value="2" >Associate Professor</option>
            <option value="3" >Assistant Professor</option>
		</select>
		</div> 
		</li>

        <li id="li_18" >
		<label class="description" for="course_drop_down">Course</label>
		<div>
		<select class="element select medium" id="course_drop_down" name="course_drop_down">
			<option value="" selected="selected"></option>
		</select>
		</div> 
		</li>


        <li id="li_20" >
                    <label class="description" for="term_drop_down">Term </label>
                    <div>
                        <select class="element select medium" id="term_drop_down" name="term_drop_down">
                            <option value="" selected="selected"></option>
                        </select>
                    </div>
        </li>

        <li id="li_19" >
		<label class="description" for="section_drop_down">Section </label>
		<div>
		<select class="element select medium" id="section_drop_down" name="section_drop_down">
			<option value="" selected="selected"></option>
		</select>
		</div> 
		</li>



        <li id="li_11" >
		<label class="description" for="research_ints">Research Interests </label>
		<div>
			<input id="research_ints" name="research_ints" class="element text large" type="text" maxlength="255" value=""/>
		</div> 
		</li>
			
					<li class="buttons">
			    <input type="hidden" name="form_id" value="528101" />
			    
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
		</li>
			</ul>
		</form>	
		<div id="footer">
			Sharp Cheddar
		</div>
	</div>
	<img id="bottom" src="bottom.png" alt="">
	</body>
</html>